<template>
  <div class="product-add">
    <!--form表单-->
    <el-form size="small" ref="form" :model="form" label-width="200px">
      <!--     <el-form-item label="是否开启优惠券抵扣" prop="isCoupon">
        <el-switch v-model="form.isCoupon"></el-switch> -->
      <!-- <p>注：如需使用分销功能必须在 [分销中心 - 分销设置] 中开启</p> -->
      <!--      </el-form-item> -->
      <el-form-item label="是否开启分销" prop="isDistribution">
        <el-switch v-model="form.isAgent"></el-switch>
        <!-- <p>注：如需使用分销功能必须在 [分销中心 - 分销设置] 中开启</p> -->
      </el-form-item>
      <el-form-item label="是否开启积分抵扣" prop="isDistribution">
        <el-switch v-model="form.isPoint"></el-switch>
        <!-- <p>注：如需使用分销功能必须在 [分销中心 - 分销设置] 中开启</p> -->
      </el-form-item>

      <el-form-item label="砍价规则">
        <div class="max-w460">
          <el-input
            v-model="form.bargainRules"
            type="textarea"
            rows="10"
          ></el-input>
        </div>
      </el-form-item>

      <!--提交-->
      <div class="common-button-wrapper">
        <el-button size="small" type="primary" @click="onSubmit"
          >提交</el-button
        >
      </div>
    </el-form>
  </div>
</template>

<script>
import BargainApi from "@/api/bargain.js";
export default {
  data() {
    return {
      /*form表单数据*/
      form: {
        isAgent: "false",
        // isCoupon: 'false',
        isPoint: "false",
      },
    };
  },
  created() {
    this.getData();
  },

  methods: {
    /*获取数据*/
    getData() {
      let self = this;
      BargainApi.settingDetail({}, true)
        .then((res) => {
          self.form = res.data;
          if (self.form.isCoupon == "true") {
            self.form.isCoupon = true;
          }
          if (self.form.isAgent == "true") {
            self.form.isAgent = true;
          }
          if (self.form.isPoint == "true") {
            self.form.isPoint = true;
          }
        })
        .catch((error) => {});
    },

    /*提交表单*/
    onSubmit() {
      let self = this;
      let params = this.form;
      BargainApi.editSetting(params, true)
        .then((data) => {
          ElMessage({
            message: "设置成功",
            type: "success",
          });
          this.getData();
        })
        .catch((error) => {});
    },
  },
};
</script>

<style></style>
